package com.twu.biblioteca.menus;

import com.twu.biblioteca.InputController;
import com.twu.biblioteca.OutputController;
import com.twu.biblioteca.User;
import com.twu.biblioteca.UserList;

import java.io.IOException;

public class UserMenu implements Menu {
    private final OutputController outputController;
    private final InputController inputController;
    private final UserList userList;
    private int nextMenu;

    public UserMenu(OutputController outputController, InputController inputController, UserList userList) {
        this.outputController = outputController;
        this.inputController = inputController;
        this.userList = userList;
    }

    @Override
    public void displayMenu() {


    }

    @Override
    public void runCommand() throws IOException {
        outputController.drawMessage("Please enter you library id.");
        final int libraryNumber = inputController.readLibraryNumber();
        outputController.drawMessage("Please enter your password.");
        final String password = inputController.readPassword();

        if (userList.setLoggedInUser(new User(libraryNumber, password))) {
            outputController.drawMessage("Thank you. You are logged in.");
        }else{
            outputController.drawMessage("I'm sorry your email or password was incorrect");
        }
        nextMenu = 1;
    }

    @Override
    public void getInput() throws IOException {
    }

    @Override
    public int getNextMenu() {
        return nextMenu;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean mustBeLoggedIn() {
        return false;
    }
}
